package com.baiyang.app.ui.mine.commentRecord;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.baiyang.app.tool.LogUtils;
import com.baiyang.app.tool.net.SendMsgUtil;
import com.baiyang.app.tool.net.Urls;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Response;

public class RecordCommentService {
    private Context context;
    private RecordCommentViewModel viewModel;
    public RecordCommentService(Context context,RecordCommentViewModel viewModel){
        this.context = context;
        this.viewModel = viewModel;
    }

    /**
     * 获取历史评论记录
     * @param pageOn
     * @param id
     */
    public void selectRecord(int pageOn, String id) {
        JSONObject object = new JSONObject();
        object.put("pageOn",pageOn);
        object.put("userId",id);
        object.put("pageSize",10);
        new SendMsgUtil(){
            @Override
            public void deal(Call call, Response response) throws IOException {
                if(response.code() == 200){
                    String str = response.body().string();
                    LogUtils.i("getCommentRecord",str);
                    viewModel.setCommentLists(JSONObject.parseObject(str));
                }else{
                    LogUtils.i("getCommentRecord","code:" + response.code());
                }
            }
            @Override
            public void dealFailure(Call call, IOException e) throws IOException {
                LogUtils.i("getCommentRecord","IOException:" + e.getLocalizedMessage());
            }
        }.sendPost(Urls.COMMENT.GET_COMMENT_RECORD,object);
    }
}
